<?php
class addressdao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function get_street_by_id($id){
		$this->db->select('*');
		$this->db->from('street');
		$this->db->where('street_id',$id);
		$query = $this->db->get();
		$street = $query->row();
		return $street;
	}
	
	public function get_all_streets(){
		$this->db->select('*');
		$this->db->from('street');
		$query = $this->db->get();
		$streets = $query->result();
		return $streets;
	}
	
	public function get_distict_by_id($id){
		$this->db->select('*');
		$this->db->from('district');
		$this->db->where('district_id',$id);
		$query = $this->db->get();
		$district = $query->row();
		return $district;
	}
	
	public function get_all_districts(){
		$this->db->select('*');
		$this->db->from('district');
		$this->db->where('district_id',$id);
		$query = $this->db->get();
		$districts = $query->result();
		return $districts;
	}
	
	public function get_city_by_name($name){
		$this->db->select('*');
		$this->db->from('city');
		$this->db->where('city_name',$name);
		$query = $this->db->get();
		$city = $query->row();
		return $city;
	}

	public function get_all_cities(){
		$this->db->select('*');
		$this->db->from('city');
		$query = $this->db->get();
		$cities = $query->result();
		return $cities;
	}
	
	public function get_neighborhood_by_id($id){
		$this->db->select('*');
		$this->db->from('neighborhood');
		$this->db->where('neighborhood_id',$id);
		$query = $this->db->get();
		$neighborhood = $query->row();
		return $neighborhood;
	}
	
	public function get_all_neighborhoods(){
		$this->db->select('*');
		$this->db->from('neighborhood');
		$query = $this->db->get();
		$neighborhoods = $query->result();
		return $neighborhoods;
	}
	
	public function get_user_address_by_id($id){
		$this->db->select('*');
		$this->db->from('user_address');
		$this->db->where('user_id',$id);
		$query = $this->db->get();
		$user_address = $query->row();
		return $user_address;
	}
	
	public function get_address($user_id){
		$this->db->select('*');
		$this->db->from('user_address');
		$query = $this->db->get();
		$user_addresses = $query->result();
		return $user_addresses;
		
		if (intval($neigborhood_id) > 0) {
			$this->db->select('*');
			$this->db->from('user_address');
			$this->db->join('street', 'user_address.street_id = street.street_id');
			$this->db->join('neighborhood', 'neighborhood.neighborhood_id = street.neighborhood_id');
			$this->db->join('district', 'neighborhood.distrcit_id = district.distrcit_id');
			$this->db->join('city', 'city.city_name = district.city_name');
			$this->db->where('user_address.user_id', $user_id);
			$query = $this->db->get();
			$result = $query->result();
			return $result;
		}	
		return null;
	}	
	
	public function get_all_user_addresses(){
		$this->db->select('*');
		$this->db->from('user_address');
		$query = $this->db->get();
		$user_addresses = $query->result();
		return $user_addresses;
	}
}
?>